
import time
import redis


import logging

logging.basicConfig(level = logging.INFO,format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s')

logger = logging.getLogger(__name__)

class Sentry:

    def __init__(self) -> None:

        self.r = redis.Redis(host='localhost', port=6379, db=0)

    def sentry_scan_rfid(self): # 监测扫描结果

        # 持续监测集合元素数量
        while True:
            # 获取集合的初始元素数量
            initial_count = self.r.scard('now_esp_set')

            logger.info("initial_count: {}".format(initial_count))

            # 延时1秒
            time.sleep(1)
            # 获取当前集合的元素数量
            current_count = self.r.scard('now_esp_set')
            
            # 如果1秒内集合元素数量没有增长，则打印“打扫完成”并退出循环
            if current_count == initial_count:
            
                self.r.publish('start_inventory_channel', 'False') # 发送终止扫描任务

                break

if __name__ == "__main__":


    Sentry().sentry_scan_rfid()

